﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using ModuleDALCore;
using System.Data;
namespace DAL
{
    public class PHONGBANDAO:DALBase
    {
        public PHONGBANDAO()
        {
            this.OpenConnect();
        }
        private DataTable dt;
        private string _SpName;

        public string SpName
        {
			get { return "SpPhongBan"; }
            set { _SpName = value; }
        }
        //get all data
        public List<PHONGBAN> GetListPB()
        {
            List<PHONGBAN> benhnhanc = new List<PHONGBAN>();
            dt = new DataTable();
            try
            {

                dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new PHONGBAN(), null), ConvertClassToArray.GetValues(new PHONGBAN(), 0));
                benhnhanc = (List<PHONGBAN>)ConvertDatatableToList.ConvertTo<PHONGBAN>(dt);
            }
            catch { throw new InvalidExpressionException("Msg1: Can't list PB"); }
            return benhnhanc;
        }
		public DataTable GetListPBs()
		{
			dt = new DataTable();
			try
			{

				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new PHONGBAN(), null), ConvertClassToArray.GetValues(new PHONGBAN(), 0));
				
			}
			catch { throw new InvalidExpressionException("Msg1: Can't list PB"); }
			return dt;
		}
        public String CreateNewID()
        {

            try
            {
                return "PB"+DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(new PHONGBAN(), null), ConvertClassToArray.GetValues(new PHONGBAN(), 1));
              
            }
            catch { throw new InvalidExpressionException("Msg1: Can't Create new PB"); }
        }
        public bool INSERT(PHONGBAN pb)
        {

            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(pb, null), ConvertClassToArray.GetValues(pb, 2)) == 1);

            }
            catch { throw new InvalidExpressionException("Msg1: Can't Create new PB"); }
        }
        public bool UPDATE(PHONGBAN pb)
        {

            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(pb, null), ConvertClassToArray.GetValues(pb, 3)) == 1);

            }
            catch { throw new InvalidExpressionException("Msg1: Can't update  PB"); }
        }
        public bool DELETE(PHONGBAN pb)
        {

            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(pb, null), ConvertClassToArray.GetValues(pb, 4)) == 1);

            }
            catch { throw new InvalidExpressionException("Msg1: Can't Delete  PB"); }
        }
    }
}
